package com.sky.service.impl;

import com.sky.mapper.DishMapper;
import com.sky.mapper.OrderMapper;
import com.sky.mapper.ReportMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.service.OrderService;
import com.sky.service.WorkSpaceService;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//工作台相关功能
@Service
public class WorkSpaceServiceImpl implements WorkSpaceService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    ReportMapper reportMapper;

    @Autowired
    SetmealMapper setmealMapper;
    @Autowired
    DishMapper dishMapper;

    //查询订单管理数据
    @Override
    public OrderOverViewVO getOrderOverView() {
        //全部订单数
        Integer allOrders = orderMapper.getAllOrder();
        //已取消数量
        Integer cancelledOrders = orderMapper.getCancelOrder();
        //已完成数量
       Integer completedOrders = orderMapper.getCompletedOrders();
        //待派送数量
        Integer deliveredOrders = orderMapper.getConfirmed();
        //待接单数量
        Integer waitingOrders = orderMapper.getToBeConfirmed();

        OrderOverViewVO orderOverViewVO = new OrderOverViewVO();
        orderOverViewVO.setAllOrders(allOrders);
        orderOverViewVO.setCancelledOrders(cancelledOrders);
        orderOverViewVO.setCompletedOrders(completedOrders);
        orderOverViewVO.setDeliveredOrders(deliveredOrders);
        orderOverViewVO.setWaitingOrders(waitingOrders);
        return orderOverViewVO;
    }

    @Override
    public SetmealOverViewVO getSetmealOverView() {
        //已停售套餐数量
        Integer discontinued = setmealMapper.getNumberByStatus(0);
        //已启售套餐数量
        Integer sold =  setmealMapper.getNumberByStatus(1);
        //封装
        SetmealOverViewVO setmealOverViewVO = new SetmealOverViewVO(discontinued, sold);
        setmealOverViewVO.setDiscontinued(discontinued);
        setmealOverViewVO.setSold(sold);
        return setmealOverViewVO;
    }

    @Override
    public DishOverViewVO getDishOverView() {
        //已停售菜品数量
        Integer discontinued = dishMapper.getNumberByStatus(0);
        //已启售菜品数量
        Integer sold = dishMapper.getNumberByStatus(1);

        DishOverViewVO dishOverViewVO = new DishOverViewVO(discontinued, sold);
        dishOverViewVO.setDiscontinued(discontinued);
        dishOverViewVO.setSold(sold);

        return dishOverViewVO;
    }

}
